package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.dto.CourseDto;
import com.cly.entity.Course;
import com.cly.entity.CourseUser;
import com.cly.result.JsonRequest;
import com.cly.service.ICourseService;
import com.cly.vo.CourseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程表业务层实现
 *
 * @author 春风能解释
 * <p>
 * 2024-06-06
 */
@RestController
@RequestMapping("/course")
@Tag(name = "课程表控制类", description = "课程表操作访问接口")
public class CourseController extends BaseController<ICourseService, Course> {

    /**
     * 根据条件查询课程表信息
     *
     * @param current 页码
     * @param size    页长
     * @param course  条件
     * @return JSON
     */
    @GetMapping("/list")
    @Operation(summary = "根据条件查询课程表信息")
    public JsonRequest<List<CourseVo>> lookCourse(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "课程表条件")
            Course course) {
        return baseService.lookCourse(current, size, course);
    }

    /**
     * 新增一条课程表信息
     *
     * @param courseDto 课程表信息
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "新增一条课程表信息")
    public JsonRequest<Integer> addOneCourse(
            @Parameter(description = "课程表信息", required = true)
            @RequestBody CourseDto courseDto) {
        return baseService.addOneCourse(courseDto);
    }

    /**
     * 修改一条课程表信息
     *
     * @param course 课程表信息
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改一条课程表信息")
    public JsonRequest<Integer> updateOneCourse(
            @Parameter(description = "课程表信息", required = true)
            @RequestBody Course course) {
        return baseService.updateOneCourse(course);
    }

    /**
     * 批量删除课程表信息
     *
     * @param ids 课程表id列表
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "批量删除课程表信息")
    public JsonRequest<Integer> deleteCourses(
            @Parameter(description = "课程表id列表", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deleteCourses(ids);
    }

    /**
     * 根据用户ID查询课程表信息
     *
     * @param userId 用户ID
     * @return JSON
     */
    @GetMapping("/user")
    @Operation(summary = "根据用户ID查询课程表信息")
    public JsonRequest<List<Course>> lookCourseByUser(
            @Parameter(description = "用户ID", required = true)
            @RequestParam Long userId) {
        return baseService.lookCourseByUser(userId);
    }

    /**
     * 添加用户课程关联
     *
     * @param courseUser 用户课程关联
     * @return JSON
     */
    @PostMapping("/user")
    @Operation(summary = "添加用户课程关联")
    public JsonRequest<Boolean> addCourseUser(
            @Parameter(description = "用户课程关联", required = true)
            @RequestBody CourseUser courseUser) {
        return baseService.addCourseUser(courseUser);
    }

    /**
     * 删除用户关联
     *
     * @param ids id列表
     * @return JSON
     */
    @DeleteMapping("/user")
    @Operation(summary = "删除用户关联")
    public JsonRequest<Boolean> removeCourseUser(
            @Parameter(description = "id列表", required = true)
            @RequestBody List<Long> ids) {
        return baseService.removeCourseUser(ids);
    }

}